//
//  InfoOthersTableViewCell.m
//  Liuhe
//
//  Created by zr on 2018/8/13.
//  Copyright © 2018年 zr. All rights reserved.
//

#import "InfoOthersTableViewCell.h"

@interface InfoOthersTableViewCell ()<UITextViewDelegate>

@property (nonatomic, weak)UITextView * textView;
@property (nonatomic, weak)UIView * lineView;

@end

@implementation InfoOthersTableViewCell


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    if ([super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        [self setupUI];
    }
    
    return self;
}


- (void)setupUI{
    
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    self.backgroundColor = WHITE_COLOR;
    
    UILabel * titleLabel = [UILabel new];
    
    titleLabel.textColor = BLACK_COLOR;
    titleLabel.font = [UIFont systemFontOfSize:15 * SCREENH6];
    titleLabel.text = @"----";
    
    self.titleLabel = titleLabel;
    
    [self.contentView addSubview:self.titleLabel];
    
    // 创建textView
    UITextView *textView =[[UITextView alloc]init];
    textView.backgroundColor= WHITE_COLOR;
    textView.text = @"请描述您的房屋情况";
    textView.font = [UIFont systemFontOfSize:14 * SCREENH6];
    textView.textColor = ColorWithRGB(0xbebebe);
    textView.delegate = self;
    textView.layer.borderColor = [ColorWithRGB(0xe6e6e6) CGColor];
    textView.layer.borderWidth = 1.0f;
    textView.delegate = self;
    
    self.textView = textView;
    
    [self.contentView addSubview:self.textView];
    
    UIView * lineView = [UIView new];
    
    lineView.backgroundColor = ColorWithRGB(0xe6e6e6);
    
    self.lineView = lineView;
    
    [self.contentView addSubview:self.lineView];
}


-(void)layoutSubviews{
    
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.contentView).offset(15 * SCREENH6);
        make.top.mas_equalTo(self.contentView).offset(10 * SCREENH6);
    }];
    
    [self.textView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.contentView).offset(15 * SCREENH6);
        make.trailing.mas_equalTo(self.contentView).offset(-15 * SCREENH6);
        make.height.mas_equalTo(70 * SCREENH6);
        make.top.mas_equalTo(self.titleLabel.mas_bottom).offset(12 * SCREENH6);
    }];
    
    [self.lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.trailing.mas_equalTo(self.contentView);
        make.height.mas_equalTo(2 * SCREENH6);
        make.bottom.mas_equalTo(self.contentView);
    }];
}


- (void)textViewDidEndEditing:(UITextView *)textView
{
    
    if(textView.text.length < 1){
        textView.text = @"请描述您的房屋情况";
        textView.textColor = ColorWithRGB(0xbebebe);
    }else{
        
        [textView resignFirstResponder];
        self.block(textView.text);
    }
}

- (void)textViewDidBeginEditing:(UITextView *)textView
{
    if([textView.text isEqualToString:@"请描述您的房屋情况"]){
        textView.text=@"";
        textView.textColor=[UIColor blackColor];
    }
}


- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    
    [self.textView resignFirstResponder];
    //    [self.textView endEditing:YES];
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
